home *** CD-ROM | disk | FTP | other *** search
- /*
- FILE: Journal cdev.c - based on Journal cdev.c
-
- Parts of this code Copyright (c) 1989 Symantec Corporation. All rights reserved.
-
-
- This is the cdev part of The Journal. The cdev allows configuration of The
- Journal, it also invokes the Journal driver.
-
- The cdev allows specification of the types of events journaled, the file to
- journal to (or a default), the level of time stamping.
-
- */
-
- #include "Journal cdev.h"
- #include "journalDriverInclude.h"
-
- /*----------------------
-
- Runnable
-
- should the cdev appear in the Control Panel?
-
- This implements the "macDev" message.
-
- ------------------------*/
-
- Boolean Runnable(void)
- {
- return(true);
- }
-
-
- /*----------------------
-
- New
-
- create the Journal cdev object
-
- ------------------------*/
-
- cdev *New(void)
- {
- return(new(Journal));
- }
-
-
-
- /*----------------------
-
- Init
-
- initialize the cdev. This involves seting up the control
- items according to the saved state of the cdev.
-
- The check boxes for different types of events are checked
- or unchecked according to the previous state. The button
- to set the journal file is enabled if no file is picked,
- disabled otherwise. The start/stop button is enabled and
- labled start if a file is picked, but the journal is not
- recording. It is enabled and labeled stop if the journal
- is recording. It is disabled if no file is currently
- picked
-
- ------------------------*/
-
- void Journal::Init(void)
- {
- P_JrnlState theJrnlState ;
- ControlHandle theControl ;
- int aType, i ;
- Rect aRect ;
- char *osPtr, creatStr[5] ;
-
-
- int **theFlag ;
- Handle itemHandle ;
-
- /* some feedback about the driver. This will evetually go away */
-
- GetDItem(dp, lastItem + INSTALLED_STRING, &aType, &itemHandle, &aRect) ;
- theFlag = (int**) GetResource(JRNL_DRIVER_FLAG_TYPE, JRNL_DRIVER_FLAG_ID) ;
- if ((**theFlag) == 0)
- SetIText(itemHandle, "\pDriver NOT Installed") ;
- else
- SetIText(itemHandle, "\pDriver Installed") ;
-
- /* get the journal state resource and set things up */
-
- journalState = GetResource(STATE_RES_TYPE, STATE_RES_ID) ;
- if (journalState == NULL) {
- /* error condition */
- }
- else {
- HLock(journalState) ;
- theJrnlState = (P_JrnlState)(*journalState) ;
-
- /* first set the state of the check boxe */
-
- DoSetControl(lastItem + TIME_STAMP_CHECK,
- (theJrnlState->eventFlags & TIME_STAMP_BIT)) ;
-
- /* set the active state of all buttons (except start/stop)
- to deactive if the journal is recording, active otherwise.
-
- Also set the string of the start/stop button. */
-
- if (theJrnlState->recording != 0) {
- GetDItem(dp, lastItem + START_STOP_BUTTON, &aType,
- (Handle)&theControl, &aRect) ;
- SetCTitle(theControl, STOP_STRING) ;
- SetButtonState(FALSE) ;
- }
- else {
- GetDItem(dp, lastItem + START_STOP_BUTTON, &aType,
- (Handle)&theControl, &aRect) ;
- SetCTitle(theControl, START_STRING) ;
- SetButtonState(TRUE) ;
- }
-
- /* output the string for the current journal file creator type */
-
- osPtr = (char*) &(theJrnlState->creator) ;
- creatStr[0] = 4 ;
- creatStr[1] = *osPtr++ ; creatStr[2] = *osPtr++ ;
- creatStr[3] = *osPtr++ ; creatStr[4] = *osPtr++ ;
-
- GetDItem(dp, lastItem + FILE_CREATOR_STRING, &aType, &itemHandle, &aRect) ;
- SetIText(itemHandle, creatStr) ;
-
-
-
- /* finaly set the state of the start/stop button based on
- whether there is a currently chosen journal file */
-
- GetDItem(dp, lastItem + START_STOP_BUTTON, &aType, (Handle)&theControl, &aRect) ;
- if (theJrnlState->hasFile != 0)
- HiliteControl(theControl, CONTROL_ACTIVE) ;
- else
- HiliteControl(theControl, CONTROL_INACTIVE) ;
-
- HUnlock(journalState) ;
- }
-
- inherited::Init();
- }
-
-
- /*----------------------
-
- Close
-
- Close needs to deallocate the journal state resource.
- It writes out the resource just in case it has changed.
-
- ------------------------*/
-
- void Journal::Close(void)
- {
- ChangedResource(journalState) ;
- WriteResource(journalState) ;
- ReleaseResource(journalState) ;
- inherited::Close();
- }
-
-
- /*----------------------
-
- ItemHit
-
- An active item has been hit in the cdev. Find out which
- one it was and take the appropriate action.
-
- ------------------------*/
-
- void Journal::ItemHit(int item)
- {
- ControlHandle theControl ;
- int aType, controlValue ;
- Rect aRect ;
- P_JrnlState theJrnlState ;
-
- switch (item) {
- case FILE_BUTTON:
- DoFileButton() ;
- break ;
-
- case TIME_STAMP_CHECK:
- GetDItem(dp, lastItem + item, &aType, (Handle)&theControl, &aRect) ;
- controlValue = (GetCtlValue(theControl) == CHECK_ON) ? CHECK_OFF : CHECK_ON ;
- SetCtlValue(theControl, controlValue) ;
-
- HLock(journalState) ;
- theJrnlState = (P_JrnlState)(*journalState) ;
- switch (item) {
- case TIME_STAMP_CHECK:
- if (controlValue == CHECK_ON)
- theJrnlState->eventFlags |= TIME_STAMP_BIT ;
- else
- theJrnlState->eventFlags &= ~(TIME_STAMP_BIT) ;
- break ;
- }
- HUnlock(journalState) ;
- ChangedResource(journalState) ;
- WriteResource(journalState) ;
- break ;
-
- case START_STOP_BUTTON:
- DoStartStopButton() ;
- break ;
-
- case FILE_CREATOR_BUTTON:
- DoSetFileCreator() ;
- break ;
- }
-
- }
-
-
- /*----------------------
-
- DoFileButton
-
- The user pressed the file button to select a
- journal file.
-
- Use the standard file package to get the file
- specification.
-
- ------------------------*/
-
- void Journal::DoFileButton()
- {
- Point where ;
- Rect *temp ;
- int i ;
- long dirID, procID ;
- short volNum ;
- SFReply jFile;
- OSErr err ;
-
- P_JrnlState theJrnlState ;
-
- /* center the SF dialog around the cdev dialog window */
-
- temp = &(dp->port.portRect) ;
-
- where.h = (*temp).left + ((*temp).right - (*temp).left) ;
- where.v = (*temp).top + ((*temp).bottom - (*temp).top) ;
-
- HLock(journalState) ;
- theJrnlState = (P_JrnlState)(*journalState) ;
-
- if (theJrnlState->hasFile == 0)
- SFPutFile(where, FILE_PROMPT, DEFAULT_FILE_NAME, NULL, &jFile) ;
- else
- SFPutFile(where, FILE_PROMPT, (theJrnlState->fName), NULL, &jFile) ;
-
- /* if the user give a valid file, set the start/stop button
- state to active (they can now record). Also, update the journal
- state. */
-
- if (jFile.good) {
- DoHiliteControl(lastItem + START_STOP_BUTTON, CONTROL_ACTIVE) ;
- theJrnlState->hasFile = 1 ;
- for (i = 0 ; i <= jFile.fName[0] ; i++)
- theJrnlState->fName[i] = jFile.fName[i] ;
- GetWDInfo(jFile.vRefNum, &volNum, &dirID, &procID) ;
- theJrnlState->vRefNum = volNum ;
- theJrnlState->dirID = dirID ;
- }
-
- HUnlock(journalState) ;
- ChangedResource(journalState) ;
- WriteResource(journalState) ;
- }
-
-
-
- /*----------------------
-
- DoSetFileCreator
-
- The user pressed the file button to select a
- journal file.
-
- Use the standard file package to get the file
- specification.
-
- ------------------------*/
-
- void Journal::DoSetFileCreator()
- {
- Point where ;
- Rect *temp ;
- int i ;
- SFReply jFile;
- OSErr err ;
- SFTypeList theTypes ;
- FInfo fileInfo ;
- char *osPtr, creatStr[5] ;
- Handle itemHandle ;
- int aType ;
- Rect aRect ;
-
- P_JrnlState theJrnlState ;
-
- /* center the SF dialog around the cdev dialog window */
-
- temp = &(dp->port.portRect) ;
-
- where.h = (*temp).left + ((*temp).right - (*temp).left) ;
- where.v = (*temp).top + ((*temp).bottom - (*temp).top) ;
-
-
- theTypes[0] = 'APPL' ;
- SFGetFile(where, CREATOR_PROMPT, NULL, 1, &theTypes, NULL, &jFile) ;
-
- /* if the user give a valid file, set the start/stop button
- state to active (they can now record). Also, update the journal
- state. */
-
- if (jFile.good) {
- HLock(journalState) ;
- theJrnlState = (P_JrnlState)(*journalState) ;
-
- err = GetFInfo(jFile.fName, jFile.vRefNum, &fileInfo) ;
- theJrnlState->creator = fileInfo.fdCreator ;
-
- osPtr = (char*) &(fileInfo.fdCreator) ;
- creatStr[0] = 4 ;
- creatStr[1] = *osPtr++ ; creatStr[2] = *osPtr++ ;
- creatStr[3] = *osPtr++ ; creatStr[4] = *osPtr++ ;
-
- GetDItem(dp, lastItem + FILE_CREATOR_STRING, &aType, &itemHandle, &aRect) ;
- SetIText(itemHandle, creatStr) ;
-
-
- HUnlock(journalState) ;
- ChangedResource(journalState) ;
- WriteResource(journalState) ;
- }
-
- }
-
-
-
- /*----------------------
-
- DoStartStopButton
-
- The user pressed the start/stop button. Either start
- the journal recording or stop it.
-
- ------------------------*/
-
- void Journal::DoStartStopButton(void)
- {
- ControlHandle theControl ;
- int aType, controlValue ;
- Rect aRect ;
- P_JrnlState theJrnlState ;
-
- GetDItem(dp, lastItem + START_STOP_BUTTON, &aType, (Handle)&theControl, &aRect) ;
-
- HLock(journalState) ;
- theJrnlState = (P_JrnlState)(*journalState) ;
-
- if (theJrnlState->recording != 0) {
- DoDriverStuff(FALSE) ;
- theJrnlState->recording = 0 ;
- theJrnlState->hasFile = 0 ;
- SetCTitle(theControl, START_STRING) ;
- SetButtonState(TRUE) ;
- HiliteControl(theControl, CONTROL_INACTIVE) ;
- }
- else {
- DoDriverStuff(TRUE) ;
- theJrnlState->recording = 1 ;
- SetCTitle(theControl, STOP_STRING) ;
- SetButtonState(FALSE) ;
- }
-
- HUnlock(journalState) ;
- ChangedResource(journalState) ;
- WriteResource(journalState) ;
- }
-
-
- /*----------------------
-
- SetButtonState
-
- Enable or disable the check buttons and the
- file pick button based on the parameter.
-
- ------------------------*/
-
- void Journal::SetButtonState(Boolean activate)
- {
- ControlHandle theControl ;
- int aType, activateValue ;
- Rect aRect ;
-
- if (activate)
- activateValue = CONTROL_ACTIVE ;
- else
- activateValue = CONTROL_INACTIVE ;
-
- DoHiliteControl(lastItem + TIME_STAMP_CHECK, activateValue) ;
- DoHiliteControl(lastItem + FILE_BUTTON, activateValue) ;
- }
-
-
- /*----------------------
-
- DoDriverStuff
-
- Start or stop the driver based on the parameter.
-
- If starting the journal driver, need to tell it
- what file to open. Pass the appropriate
- paramenter in a control call.
-
- ------------------------*/
-
- void Journal::DoDriverStuff(Boolean isStart)
- {
- OSErr err ;
- P_JrnlState theJrnlState ;
- int dRefNum, i ;
- JrnlFileParam params ;
-
- HLock(journalState) ;
- theJrnlState = (P_JrnlState)(*journalState) ;
-
- if (isStart) {
- err = OpenDriver(JRNL_DRVR_NAME, &dRefNum) ;
- if (err == noErr) {
- theJrnlState->driverRefNum = dRefNum ;
-
- for (i = 0 ; i <= theJrnlState->fName[0] ; i++)
- params.fName[i] = theJrnlState->fName[i] ;
- params.vRefNum = theJrnlState->vRefNum ;
- params.dirID = theJrnlState->dirID ;
- params.eventFlags = theJrnlState->eventFlags ;
- params.creator = theJrnlState->creator ;
- err = Control(dRefNum, JRNL_OPEN_FILE, ¶ms) ;
- err = Control(dRefNum, JRNL_ON, NULL) ;
- }
- }
- else
- err = Control((theJrnlState->driverRefNum), JRNL_OFF, NULL) ;
-
- HUnlock(journalState) ;
- }
-
-
-
-
- /*----------------------
-
- DoHiliteControl
-
- Set the hilite of the specified control item to theHilite.
-
- ------------------------*/
-
- void Journal::DoHiliteControl(int theItem, Boolean theHilite)
- {
- ControlHandle theControl ;
- int aType ;
- Rect aRect ;
-
- GetDItem(dp, theItem, &aType, (Handle)&theControl, &aRect) ;
- HiliteControl(theControl, theHilite) ;
- }
-
-
- /*----------------------
-
- DoSetControl
-
- Set the control value of the specified control item
- to theValue.
-
- ------------------------*/
-
- void Journal::DoSetControl(int theItem, int theValue)
- {
- ControlHandle theControl ;
- int aType ;
- Rect aRect ;
-
- GetDItem(dp, theItem, &aType, (Handle)&theControl, &aRect) ;
- SetCtlValue(theControl, theValue) ;
- }